package com.night.administration.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName: RabbitConfig
 * @Description: //TODO
 * @author: LZJ
 * @date: 2022/10/26-23:10
 * @version: v1.0
 */
@Configuration
public class RabbitConfig {
    //声明交换机
    //exchangeTopic是springboot中的名字 administration_exchange_topic是rabbitMQ中的交换机的名字
    @Bean
    public TopicExchange exchangeTopic() {
        return new TopicExchange("administration_exchange_topic");
    }

    //声明队列
    @Bean
    public Queue queueCourseArrangement() {
        return new Queue("queueCourseArrangement");
    }

    //绑定队列到交换机
    //queueCourseArrangement是方法名
    @Bean
    public Binding binding(@Qualifier("queueCourseArrangement") Queue queue, TopicExchange topicExchange) {
        return BindingBuilder.bind(queue).to(topicExchange).with("afterArrangement");
    }

    //发的消息是对象进行序列化
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }
}
